package com.ruoyi.hr.controller.hr.welfare.welfareregion;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.welfare.welfareregion.WelfareType;
import com.ruoyi.hr.service.welfare.welfareRegion.WelfareTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zeo
 * @explain 福利类型
 * @date 2019/12/19 10:48
 */
@Controller
@RequestMapping("/welfare/region/welfareType")
public class WelfareTypeController extends BaseController {
    @Autowired
    WelfareTypeService welfareTypeService;

    private String prefix = "hr/welfare/welfareregion/welfareType";

    //福利类型跳转
    @GetMapping()
    public String welfareType() {
        return prefix + "/welfareType";
    }

    /**
     * 获取分页数据以及数据总量
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WelfareType welfareType) {
        int PageNum = getNum(); //取得页数
        int pageSize = getSize(); //取得显示数
        List<WelfareType> list = null; //分页List
        int PageCount;//总数据量
        list = welfareTypeService.findWelfareType(welfareType, PageNum, pageSize);
        PageCount = welfareTypeService.findCount(welfareType);
        return getDataTable1(list, PageCount);
    }

    /**
     * 启动停用福利地区
     *
     * @param welfareType
     */
    @PostMapping("/changeLock")
    @ResponseBody
    public AjaxResult changeLock(WelfareType welfareType) {
        return toAjax(welfareTypeService.updateIsLock(welfareType));
    }

    /**
     * 新增跳转
     *
     * @return
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增操作
     *
     * @param welfareType
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(WelfareType welfareType) {
        return toAjax(welfareTypeService.insertWelfareType(welfareType));
    }

    /**
     * 修改跳转
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("edit/{id}")
    public String edit(@PathVariable("id") int id, ModelMap mmap) {
        mmap.put("welfareType",welfareTypeService.findWelfareTypeById(id));
        return prefix + "/edit";
    }

    /**
     * 修改操作
     * @param welfareType
     * @return
     */
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult edit(WelfareType welfareType){
        return toAjax(welfareTypeService.updateWelfareType(welfareType));
    }

    /**
     * 删除操作
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult edit(@Validated String ids) {
        return toAjax(welfareTypeService.deleteWelfareType(ids));
    }


}

